package xyz.xiangyushui.dao;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import xyz.xiangyushui.javaBean.consumption.ConsumptionHistory;

public class ConsumptionHistoryDao extends Dao{
	public List<ConsumptionHistory> getHistory(String userName){
		List<ConsumptionHistory> list=new LinkedList<>();
		List<Object> l = db.excuteQuery(
				"select * from consumptionHistory where userName=? ",
				new Object[] { userName });
		for (Object o : l) {
			@SuppressWarnings("unchecked")
			Map<String, Object> m = (Map<String, Object>) o;
			ConsumptionHistory rh=new ConsumptionHistory();
			rh.setTime((long) m.get("time"));
			rh.setMoney((double) m.get("money"));
			rh.setUserName((String) m.get("userName"));
			rh.setDiscount((int) m.get("discount"));
			list.add(rh);

		}
		return list;
	}
	
	public void addHistory(String userName,double money,int discount){
			db.executeUpdate("insert into consumptionHistory(userName,money,time,discount) values(?,?,?,?)", new Object[]{userName,money,new Date().getTime(),discount});
	}
}
